<html lang="en">
<head>
	<meta name="auto" content='spider'>
	<meta charset="UTF-8">
	<title>旅行社管理系统</title>
	<link rel="stylesheet" type="text/css" href="../css/base.css">
	<link rel="stylesheet" type="text/css" href="../css/information.css">
	<link rel="stylesheet" type="text/css" href="../css/guide.css">
	<link href="../css/route.css" type="text/css" rel="stylesheet">
	<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body onload="open_page()" style="height:1000px;">
	<header id='header'>
		<div class='center'>
			<nav style='overflow:hidden;'>
				<!--为了大纲清晰，所以要加个标题-->
				<h2 class="none">网站导航</h2>
			<ul class="link">
					<li ><a href="index.html">首页</a></li>
					<li ><a href="tourist.html">旅客查询</a></li>
					<li class="active"><a href="guide.html">导游查询</a></li>
					<li><a href="route_main.html">路线查询</a></li>
					<li><a href="team.html">团队查询</a></li>
				<li><a href="city_main.html">城市管理</a></li>
				</ul>
			</nav>
		</div>
	</header>
<style>
        fieldset{
            background-color: #f1f1f1;
            border: none;
            border-radius: 2px;
            margin-bottom: 12px;
            overflow: hidden;
            padding: 0 .625em;
        }

        label{
            cursor: pointer;
            display: inline-block;
            padding: 3px 6px;
            text-align: right;
            width: 150px;
            vertical-align: top;
        }

        input{
            font-size: inherit;
        }
    </style>	
	<div id="headline">
		<div class="center">
			<hgroup>
				<h2>旅行社管理系统</h2>
			</hgroup>
		</div>
	</div>


	<aside class='sidebar'>
	<div id="organ" οnclick="hideOrganDiv();">
	</div>
	</aside>

	<h2 style="text-align: center;">导游信息查询</h2>

	
		<ul >
			<li style="text-align: center;">
			<select id="choose" style="text-align: center; position: relative;height: 28px;">
			<option text ="name">按姓名查找</option>
			<option text ="id">按编号查找</option>
			</select><input id="text" type="text" style="width: 500px;
		    position: relative;
            top:0px;
            left:30px;
            height: 28px;
            border: 1px solid #cccccc;
            box-sizing: border-box;
            ">

			<button id="submit" style="height: 28px;position: relative;width: 60px;">查询</button>
			<button onClick="window.location.href = 'guide_add.html'" style="height: 28px;position: relative;">添加新导游
			</button>
			<button onClick="baobiao()" style="height: 28px;position: relative;">下载报表</button>
			
			</li>
			<table id="table" border="1" style="text-align: center;margin: auto;" cellspacing="0" cellpadding="0" class="table" >
				<thead>
				<tr>
					<th>导游号</th>
					<th>姓名</th>
					<th>性别</th>
					<th>团队数</th>
					<th>年龄</th>
					<th>职称</th>
					<th>身份证号</th>
					<th>电话</th>
					<th>备注</th>
					<th>操作</th>
				</tr>
				</thead>
			<tbody>

			</tbody>


			</table>
		</ul>
	
<script>

		var bt =document.getElementById("submit");
		var text = document.getElementById("text");
		var choose = document.getElementById("choose");
		var table=document.getElementById("table");
		function connect(url){
			var xhr=new XMLHttpRequest();
			xhr.open("POST",url,true);
			xhr.send();
			return xhr;
		}
		function baobiao(){
			window.open("http://39.108.233.68:8080/exportAllLeader");
		}

		function open_page(){
			var xhr=connect("http://39.108.233.68:8080/selAllLeader");
			xhr.onreadystatechange = function (ev2) {
				if(xhr.readyState === 4){
					if(xhr.status >= 200 && xhr.status < 300 ||xhr.status === 304){
						{
						var json = JSON.parse(xhr.responseText).data;
						console.log(json);

						for(var i=0; i<json.length; i++){
						    var tr = document.createElement("tr");
						    table.appendChild(tr);
							var c1=document.createElement("td");
							var c2=document.createElement("td");
							var c3=document.createElement("td");
							var c4=document.createElement("td");
							var c5=document.createElement("td");
							var c6=document.createElement("td");
							var c7=document.createElement("td");
							var c8=document.createElement("td");
							var c9=document.createElement("td");
							var c10=document.createElement("td");
							var c11=document.createElement("td");
							c1.innerHTML=json[i].id;
                            c2.innerHTML=json[i].name;
                            c3.innerHTML=json[i].sex;
                            c4.innerHTML=json[i].teamamount;
                            c5.innerHTML=json[i].age;
                            c6.innerHTML=json[i].level;
                            c7.innerHTML=json[i].idcard;
                            c8.innerHTML=json[i].phonenum;
                            c9.innerHTML=json[i].remark;
                            c10.innerHTML+=("<button id="+i.toString()+"delete"+">删除</button>");
                            c10.innerHTML+=("<button id="+i.toString()+"change"+">修改</button>");
                            tr.appendChild(c1);
							tr.appendChild(c2);
							tr.appendChild(c3);
							tr.appendChild(c4);
							tr.appendChild(c5);
							tr.appendChild(c6);
							tr.appendChild(c7);
							tr.appendChild(c8);
							tr.appendChild(c9);
							tr.appendChild(c10);


						 	document.getElementById(i.toString()+"delete").addEventListener("click",
						 	function(){
						 		send_id=document.getElementById(this.id).parentElement.parentElement.firstChild.innerHTML;
						 		dele(this.id,send_id);
						 });
						 	document.getElementById(i.toString()+"change").addEventListener("click",
						 	function(){
								url= "guide_change.html?id="+document.getElementById(this.id).parentElement.parentElement.childNodes[0].innerHTML;
								url+= "&name="+escape(document.getElementById(this.id).parentElement.parentElement.childNodes[1].innerHTML);
								url+= "&sex="+document.getElementById(this.id).parentElement.parentElement.childNodes[2].innerHTML;
								url+= "&teamamount="+document.getElementById(this.id).parentElement.parentElement.childNodes[3].innerHTML;
								url+= "&age="+document.getElementById(this.id).parentElement.parentElement.childNodes[4].innerHTML;
								url+= "&level="+document.getElementById(this.id).parentElement.parentElement.childNodes[5].innerHTML;
								url+= "&idcard="+document.getElementById(this.id).parentElement.parentElement.childNodes[6].innerHTML;
								url += "&phonenum="+document.getElementById(this.id).parentElement.parentElement.childNodes[7].innerHTML;
								url+= "&remark="+document.getElementById(this.id).parentElement.parentElement.childNodes[8].innerHTML;
								window.open(url);
							});
						}
					}}
					}
}
}
		function dele(id,send_id){
			url="http://39.108.233.68:8080/delOneLeader?id="+send_id;
			var xhr=connect(url);
			xhr.onreadystatechange = function (ev2) {
				if(xhr.readyState === 4){
					if(xhr.status >= 200 && xhr.status < 300 ||xhr.status === 304){
						{
							document.getElementById(id).parentElement.parentElement.parentElement.removeChild(document.getElementById(id).parentElement.parentElement);
						}
					}
				}
			}
		}
		function clr(){
				var rowNum=table.rows.length;
			    for(var i=1;i<rowNum;i++){
         			table.deleteRow(i);
         			rowNum=rowNum-1;
         			i=i-1;
        		}
		}
		bt.onclick=function f(){
				clr();
				//按姓名查找的url
				if(choose.options[choose.selectedIndex].text=="按姓名查找"){
				var xhr=connect("http://39.108.233.68:8080/selSomeLeader?key="+text.value);
				xhr.onreadystatechange = function (ev2){
				if(xhr.readyState === 4){
					if(xhr.status >= 200 && xhr.status < 300 ||xhr.status === 304){
						{
				var json = JSON.parse(xhr.responseText).data;
				for(var i=0; i<json.length; i++){
					var tr = document.createElement("tr");
					var c1=document.createElement("td");
					var c2=document.createElement("td");
					var c3=document.createElement("td");
					var c4=document.createElement("td");
					var c5=document.createElement("td");
					var c6=document.createElement("td");
					var c7=document.createElement("td");
					var c8=document.createElement("td");
					var c9=document.createElement("td");
					var c10=document.createElement("td");
					var c11=document.createElement("td");
					c1.innerHTML=json[i].id;
                    c2.innerHTML=json[i].name;
                    c3.innerHTML=json[i].sex;
                    c4.innerHTML=json[i].teamamount;
                    c5.innerHTML=json[i].age;
                    c6.innerHTML=json[i].level;
                    c7.innerHTML=json[i].idcard;
                    c8.innerHTML=json[i].phonenum;
                    c9.innerHTML=json[i].remark;
                    c10.innerHTML+=("<button id="+i.toString()+"delete"+">删除</button>");
                    c10.innerHTML+=("<button id="+i.toString()+"change"+">修改</button>");
                    tr.appendChild(c1);
					tr.appendChild(c2);
					tr.appendChild(c3);
					tr.appendChild(c4);
					tr.appendChild(c5);
					tr.appendChild(c6);
					tr.appendChild(c7);
					tr.appendChild(c8);
					tr.appendChild(c9);
					tr.appendChild(c10);
					table.appendChild(tr);
					document.getElementById(i.toString()+"delete").addEventListener("click",
					function(){
						send_id=document.getElementById(this.id).parentElement.parentElement.firstChild.innerHTML;
						dele(this.id,send_id);
						});
					document.getElementById(i.toString()+"change").addEventListener("click",
						function(){
							alert(document.getElementById(this.id).parentElement.parentElement.firstChild.innerHTML);
							//var url="guide_change.html?id=";
							// url+=document.getElementById(this.id).parentElement.parentElement.firstChild.innerHTML;
							// url+=&

						window.open(url);
						});
				}}}}}}
				else{
				var xhr=connect("http://39.108.233.68:8080/selOneLeader?id="+text.value);

				xhr.onreadystatechange = function (ev2) {
				if(xhr.readyState === 4){
					if(xhr.status >= 200 && xhr.status < 300 ||xhr.status === 304){
						{

				var json = JSON.parse(xhr.responseText).data;
				var tr = document.createElement("tr");
				var c1=document.createElement("td");
				var c2=document.createElement("td");
				var c3=document.createElement("td");
				var c4=document.createElement("td");
				var c5=document.createElement("td");
				var c6=document.createElement("td");
				var c7=document.createElement("td");
				var c8=document.createElement("td");
				var c9=document.createElement("td");
				var c10=document.createElement("td");
				c1.innerHTML=json.id;
                c2.innerHTML=json.name;
                c3.innerHTML=json.sex;
                c4.innerHTML=json.teamamount;
                c5.innerHTML=json.age;
                c6.innerHTML=json.level;
                c7.innerHTML=json.idcard;
                c8.innerHTML=json.phonenum;
                c9.innerHTML=json.remark;
                c10.innerHTML+=("<button id="+'0'+"delete"+">删除</button>");
                c10.innerHTML+=("<button id="+'0'+"change"+">修改</button>");
                tr.appendChild(c1);
				tr.appendChild(c2);
				tr.appendChild(c3);
				tr.appendChild(c4);
				tr.appendChild(c5);
				tr.appendChild(c6);
				tr.appendChild(c7);
				tr.appendChild(c8);
				tr.appendChild(c9);
				tr.appendChild(c10);
				table.appendChild(tr);
				document.getElementById(i.toString()+"delete").addEventListener("click",
				function(){
						send_id=document.getElementById(this.id).parentElement.parentElement.firstChild.innerHTML;
						dele(this.id,send_id);
						});
				document.getElementById(i.toString()+"change").addEventListener("click",
				function(){
						window.open("guide_change.html?id="+document.getElementById(this.id).parentElement.parentElement.firstChild.innerHTML);
						});}}}}}}
</script>
	<div style="height: 200px"></div>
	<footer id='foot'>
		<div class="top">

			<h1>欢迎使用SUN旅行社</h1>

		</div>
		<div class="bottom">
			SUN旅行社 |  | 旅行经营许可证
		</div>
	</footer>
</body>
</html>